package com.aaa.Dao;

import com.aaa.Entity.Film;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public class FilmDao {
    @Autowired
    protected JdbcTemplate jdbcTemplate;
    private RowMapper<Film> rowMapper= new RowMapper<Film>() {
        public Film mapRow(ResultSet resultSet, int i) throws SQLException {
            Film film = new Film();
            film.setFid(resultSet.getInt("fid"));
            film.setFname(resultSet.getString("fname"));
            film.setPrice(resultSet.getString("price"));
            return film;
        }
    };
    public List<Film> select(){
        String sql = "select fid,fname,price from film";
        List<Film> query = jdbcTemplate.query(sql, rowMapper);
        return query;
    }
}
